{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "e2fb7e5c-20d1-4ef8-9dd7-e7f096ccf84c",
   "metadata": {},
   "outputs": [],
   "source": [
    "class Person:\n",
    "    __idcards=[]\t#私有变量\n",
    "    names=[]\t    #公开变量\n",
    "    def __init__(self,name=\"no name\"):\n",
    "        print(\"__init__\"+\" Hello \"+name)\n",
    "        self.names.append(name)\n",
    "    def __call__(self,name):\n",
    "        print(\"__call__\"+\" Hello \"+name)\n",
    "        self.names.append(name)\n",
    "    def hello(self):\n",
    "        for i in range(len(self.names)):\n",
    "            print(\" hello \"+self.names[i])\n",
    "        for name in self.names:\n",
    "            print(\" hello \"+name)\n",
    "    def __idcard(self):  # 私有方法\n",
    "        for card in self.__idcards:\n",
    "            print(card)\n",
    "\n",
    "    def add_idcard(self, card):  # 添加一个公共方法来管理私有变量\n",
    "        self.__idcards.append(card)\n",
    "\n",
    "    def show_idcards(self):  # 添加一个公共方法来调用私有方法\n",
    "        self.__idcard()\n",
    "    def get_cnt(self):\n",
    "        return len(self.names)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "5ceee956-3f52-4c91-af6a-a91b1aeae6bc",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "__init__ Hello no name\n",
      "__call__ Hello lisi\n",
      " hello no name\n",
      " hello lisi\n",
      " hello no name\n",
      " hello lisi\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "2"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "namelist = Person()\n",
    "namelist(\"lisi\")\n",
    "namelist.hello()\n",
    "namelist.get_cnt()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "8abd490e-8094-4d37-897d-5f71e2c3f53b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "123456\n"
     ]
    }
   ],
   "source": [
    "namelist.add_idcard(\"123456\")\n",
    "namelist.show_idcards()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d3acc980-f7cc-45de-a751-183d4ac96bf7",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
